package br.com.webprojeto.colecoes;



import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.webprojeto.basicas.*;
import br.com.webprojeto.interfaces.*;

public class ColecaoNotaFiscal implements InterfaceColecaoNotaFiscal {
 
	 
	
	public void adicionarNotaFiscal(NotaFiscal Nf) {
		Session sessao = HibernateUtil.getSessionFactory().openSession();
		sessao.beginTransaction();
		sessao.saveOrUpdate(Nf);
		sessao.getTransaction().commit();
		sessao.getSessionFactory().close();
	}
	 
	
	public List<NotaFiscal> listarNotaFiscal() {
		Session sessao = HibernateUtil.getSessionFactory().openSession();
		sessao.beginTransaction();
		Query consulta = sessao.createQuery("from NotaFiscal");
		sessao.getSessionFactory().close();
		return consulta.list();
	}
	 
	
	public NotaFiscal procurarNotaFiscal(long codNotafiscal) {
		Session sessao = HibernateUtil.getSessionFactory().openSession();
		sessao.beginTransaction();
		NotaFiscal Nf = (NotaFiscal) sessao.load(NotaFiscal.class, codNotafiscal);
		sessao.getTransaction().commit();
		sessao.getSessionFactory().close();
		return Nf;
	}
	 
	
	public void atualiazarNotaFiscal(NotaFiscal Nf) {
		Session sessao = HibernateUtil.getSessionFactory().openSession();
		sessao.beginTransaction();
		sessao.update(Nf);
		sessao.getTransaction().commit();
		sessao.getSessionFactory().close();
	}
	 
}
 
